home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-05-21 | 4.3 KB | 122 lines | [TEXT/ttxt] |
- --<<<-
- -- Filename:
- -- modelcar.sx
-
- -- Other Files Required:
- -- graphble.sx
-
- -- Purpose:
- -- Class definition for the graphable ModelCar class and title container.
-
- -- Specialized Classes:
- -- ModelCar
-
- -- Instructions to User:
- -- Defines the model car class, which is an object representing a car model.
- -- A ModelCar title container can be dropped into a Grapher.
-
- -- Author:
- -- Steve Gano, Dionn Stewart, Ray Davis
-
- in module Autofinder
-
- if (not isDefined AxisProperty) do fileIn theScriptDir name:"axisprop.sx"
- if (not isDefined Graphable) do fileIn theScriptDir name:"graphble.sx"
-
- -- Class ModelCar is a simple aggregate of data properties.
- class ModelCar (Graphable)
- instance variables
- name -- a string, the name of the ModelCar
- classification -- a string, the type of ModelCar (e.g., "Station Wagon")
- modelyear -- an integer, the year of the ModelCar
- baseprice -- an integer, the base sticker price of the ModelCar
- averageprice -- an integer, the average price paid for the ModelCar
- fiveyeartradein -- an integer, the projected 5-year trade in value of the ModelCar
- citymileage -- an integer, miles per gallon, city driving
- highwaymileage -- an integer, miles per gallon, highway driving
- combinedmileage -- an integer, miles per gallon, city & highway driving
- firstyearservicecost -- an integer, average service cost in first year
- cargocapacity -- an integer, cubic feet of storage
- zerotosixty -- an integer, number of seconds to accelerat to 60 mph
- sixtytozero -- an integer, number of feet to stop from 60 mph
- class methods
- method init self #rest args -> (
- apply nextMethod self args
- local carProperties := #(
- @averageprice: #("Average Price", "dollars", 15000, 30000,averagePriceGetter),
- @baseprice: #("Base Price", "dollars", 10000, 30000,basePriceGetter),
- @cargocapacity: #("Cargo Capacity", "cu. ft.", 5.0, 20.0,cargoCapacityGetter),
- @citymileage: #("City Mileage", "MPG", 15, 25,cityMileageGetter),
- @combinedmileage:#("Combined Mileage", "MPG", 20, 30,combinedMileageGetter),
- @firstyearservicecost:#("First Year Service Cost", "dollars", 100, 400, firstYearServiceCostGetter),
- @fiveyeartradein:#("Five Year Trade In", "dollars", 8000, 40000,fiveYearTradeInGetter),
- @highwaymileage:#("Highway Mileage", "MPG", 20, 35,highwayMileageGetter),
- @sixtytozero: #("Stopping Distance", "feet", 100, 200,sixtyToZeroGetter),
- @zerotosixty: #("Zero to Sixty", "secs.", 5.0, 15.0,zeroToSixtyGetter)
- )
- forEachBinding carProperties (key val arg ->
- local prop:= new AxisProperty axisTarget:val[1] \
- minValue:val[3] maxValue:val[4] units:val[2] name:key
- prop.minTarget:= prop.minValue as string
- prop.maxTarget:= prop.maxValue as string
- prop.getterFn :=val[5]
- append self.axisProperties prop
- ) self
- self.axisProperties
- )
- -- Allow quick "positional argument" initialization.
- method makeModelCar self averageprice baseprice cargocapacity citymileage \
- classification combinedmileage firstyearservicecost fiveyeartradein \
- highwaymileage modelyear name sixtytozero zerotosixty thumbnail ->
- (
- local newCar := object (ModelCar)
- thumbnail:thumbnail
- settings
- name:name
- classification:classification
- modelyear:modelyear
- baseprice:baseprice
- averageprice:averageprice
- fiveyeartradein:fiveyeartradein
- citymileage:citymileage
- highwaymileage:highwaymileage
- combinedmileage:combinedmileage
- firstyearservicecost:firstyearservicecost
- cargocapacity:cargocapacity
- zerotosixty:zerotosixty
- sixtytozero:sixtytozero
- end
- newCar
- )
- end
-
- method afterinit self {class ModelCar} #rest args ->
- (
- -- if the modelcar is dropped on thejunkyard
- self.dropAction:= (aData draggite loc ->
- -- Hack to make adjustment for bitmap
- local spot := new point x:(loc.x + 50) y:(loc.y + 50)
- if (inside draggite.presentedby.dropspace spot) then
- (
- local traveltime:= 12
-
- -- have the modelcar drive off
- travel draggite (new point x:700 y:loc.y) traveltime
-
- -- Remove myself from the graph
- addTimeCallback draggite.travelclock (d -> removeFromGraph d.presentedby d) \
- draggite #() (draggite.travelclock.time + traveltime) true
- )
- else
- (
- -- otherwise have the car return to its position
- local list := #(draggite)
- graphObjects draggite.presentedby list
- )
- )
- self
- )
-
- -->>>
- "Compiled modelcar.sx"
-